home *** CD-ROM | disk | FTP | other *** search
- /*$T list.c GC 1.137 08/09/02 17:47:18 */
-
- /*$6
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
-
- #include "zgl.h"
- #include "list.h"
-
- static char *op_table_str[] =
- {
- #define ADD_OP(a, b, c) "gl"#a " "#c,
-
- #include "opinfo.h"
- };
-
- static void (*op_table_func[]) (GLContext *, GLParam *) =
- {
- #define ADD_OP(a, b, c) glop ## a,
-
- #include "opinfo.h"
- };
-
- static int op_table_size[] =
- {
- #define ADD_OP(a, b, c) b + 1,
-
- #include "opinfo.h"
- };
-
- /* */
-
- GLContext *gl_get_context(void) {
- return gl_ctx;
- }
-
- /* */
- GLList *find_list(GLContext *c, unsigned int list) {
- return c->shared_state.lists[list];
- }
-
- /* */
- void delete_list(GLContext *c, int list) {
- GLParamBuffer *pb, *pb1;
- GLList *l;
-
- l = find_list(c, list);
- assert(l != NULL);
-
- /* free param buffer */
- pb = l->first_op_buffer;
- while(pb != NULL) {
- pb1 = pb->next;
- free(pb);
- pb = pb1;
- }
-
- free(l);
- c->shared_state.lists[list] = NULL;
- }
-
- /* */
- GLList *alloc_list(GLContext *c, int list) {
- GLList *l;
- GLParamBuffer *ob;
-
- l = calloc(1, sizeof(GLList));
- ob = calloc(1, sizeof(GLParamBuffer));
-
- ob->next = NULL;
- l->first_op_buffer = ob;
-
- ob->ops[0].op = OP_EndList;
-
- c->shared_state.lists[list] = l;
- return l;
- }
-
- /* */
- void gl_print_op(FILE *f, GLParam *p) {
- int op;
- char *s;
-
- op = p[0].op;
- p++;
- s = op_table_str[op];
- while(*s != 0) {
- if(*s == '%') {
- s++;
- switch(*s++) {
- case 'f': fprintf(f, "%g", p[0].f); break;
- default: fprintf(f, "%d", p[0].i); break;
- }
-
- p++;
- }
- else {
- fputc(*s, f);
- s++;
- }
- }
-
- fprintf(f, "\n");
- }
-
- /* */
- void gl_compile_op(GLContext *c, GLParam *p) {
- int op, op_size;
- GLParamBuffer *ob, *ob1;
- int index, i;
-
- op = p[0].op;
- op_size = op_table_size[op];
- index = c->current_op_buffer_index;
- ob = c->current_op_buffer;
-
- /* we should be able to add a NextBuffer opcode */
- if((index + op_size) > (OP_BUFFER_MAX_SIZE - 2)) {
- ob1 = calloc(1, sizeof(GLParamBuffer));
- ob1->next = NULL;
-
- ob->next = ob1;
- ob->ops[index].op = OP_NextBuffer;
- ob->ops[index + 1].p = (void *) ob1;
-
- c->current_op_buffer = ob1;
- ob = ob1;
- index = 0;
- }
-
- for(i = 0; i < op_size; i++) {
- ob->ops[index] = p[i];
- index++;
- }
-
- c->current_op_buffer_index = index;
- }
-
- /* */
- void gl_add_op(GLParam *p) {
- GLContext *c = gl_get_context();
- int op;
-
- op = p[0].op;
- if(c->exec_flag) {
- op_table_func[op](c, p);
- }
-
- if(c->compile_flag) {
- gl_compile_op(c, p);
- }
-
- if(c->print_flag) {
- gl_print_op(stderr, p);
- }
- }
-
- /* this opcode is never called directly */
- void glopEndList(GLContext *c, GLParam *p) {
- assert(0);
- }
-
- /* this opcode is never called directly */
- void glopNextBuffer(GLContext *c, GLParam *p) {
- assert(0);
- }
-
- /* */
- void glopCallList(GLContext *c, GLParam *p) {
- GLList *l;
- int list, op;
-
- list = p[1].ui;
- l = find_list(c, list);
- if(l == NULL) {
- gl_fatal_error("list %d not defined", list);
- }
-
- p = l->first_op_buffer->ops;
-
- while(1) {
- op = p[0].op;
- if(op == OP_EndList) {
- break;
- }
-
- if(op == OP_NextBuffer) {
- p = (GLParam *) p[1].p;
- }
- else {
- op_table_func[op](c, p);
- p += op_table_size[op];
- }
- }
- }
-